// my_other/xianxiaxq/xianxiaxq.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({

    /**
     * 页面的初始数据
     */
    ...request,
    data: {
        yuming: yuming,
        heights: '',
        title: "检查详情",
        checkresult: [{
                value: 1,
                name: '全部符合',
                checked: false
            },
            {
                value: 2,
                name: '基本符合',
                checked: false
            },
            {
                value: 3,
                name: '不符合',
                checked: false
            }
        ],
        reschuli: [{
                value: 1,
                name: '通过',
                checked: false
            },
            {
                value: 2,
                name: '警告',
                checked: false
            },
            {
                value: 3,
                name: '行政指导',
                checked: false
            },
            {
                value: 4,
                name: '立案调查',
                checked: false
            },
            {
                value: 5,
                name: '限期改正',
                checked: false
            }
        ],
        huifu_kai: false,
        photo: [],
        wuphoto: [],
        huifu_con: '',
        zuihuista: '', //最后一条回复的状态
        fuid: ''
    },
    huifu_cons(e) {
        this.setData({
            huifu_con: e.detail.value
        })
    },
    // 点击回复弹窗
    huifu() {
        this.setData({
            huifu_kai: !this.data.huifu_kai,
            huifu_con: '',
            photo: [],
            wuphoto: []
        })
    },
    xinjian() {
        this.setData({
            huifu_kai: false,
            huifu_con: '',
            photo: [],
            wuphoto: []
        })
    },
    // 上传
    chuan(e) {
        var that = this
        var pics = [];
        var wuphoto = this.data.wuphoto;
        this.myChooseImage(9).then(res => {
            const tempFilePaths = res.tempFilePaths
            for (var i = 0; i < tempFilePaths.length; i++) {
                pics.push(tempFilePaths[i])
            }
            if ((pics.length) + (that.data.photo.length) > 9) {
                wx.showToast({
                    title: '最多可上传' + 9 + "张",
                    icon: 'none'
                })
            } else {
                for (var i = 0; i < tempFilePaths.length; i++) {
                    (function (i) { // 注意这里是形参
                        setTimeout(function () {
                            that.wuduoupimg(tempFilePaths[i]).then(res => {
                                var data = JSON.parse(res.data)
                                var urls = data.httpUrl + data.imgUrl
                                var wuurl = data.imgUrl
                                // wuphoto = wuphoto.concat(data.imgUrl + ",")
                                that.setData({
                                    photo: that.data.photo.concat(urls),
                                    wuphoto: that.data.wuphoto.concat(wuurl),
                                    // wuphoto: wuphoto
                                });
                            })
                        }, 800 * i); // 还是每秒执行一次，不是累加的
                    })(i) // 注意这里是实参，这里把要用的参数传进去
                }
            }
        })
    },
    // 差掉
    chadiao(e) {
        var index = e.currentTarget.dataset.index
        var photo = this.data.photo;
        var wuphoto = this.data.wuphoto;
        var dd = wuphoto.split(",")
        console.log(dd)
        photo.splice(index, 1)
        dd.splice(index, 1)
        var rr = dd.join(",")
        this.setData({
            photo: photo,
            wuphoto: rr
        })
    },
    fangda() {
        console.log('点击了放大！')
        wx.previewImage({
            urls: [this.data.dibu_img]
        })
    },
    duofan(e) {
        var img = e.currentTarget.dataset.img
        var list = e.currentTarget.dataset.list
        var arr = []
        for (let i in list) {
            arr.push(list[i]); //属性
        }
        wx.previewImage({
            current: img,
            urls: arr
        })
    },
    // 提交回复
    tijiao() {
        if (this.data.huifu_con == '') {
            wx.showToast({
                title: '请输入回复内容哦',
                icon: 'none'
            })
        } else if (this.data.photo.length == 0) {
            wx.showToast({
                title: '请上传图片哦',
                icon: 'none'
            })
        } else {
            this.jiekou()
        }
    },
    // 回复的接口
    jiekou() {
        var wuphoto = this.data.wuphoto.toString()
        this.myRequest(yuming + 'shop/shop_xuncha_hfadd', {
            shopId: wx.getStorageSync('shopId'),
            offpatrolId: this.data.xqList.id,
            hf_text: this.data.huifu_con,
            hf_images: wuphoto
        }, 'POST').then(res => {
            wx.showToast({
                title: res.data.msg,
                icon: 'none'
            })
            if (res.data.code == 200) {
                var that = this
                setTimeout(function () {
                    that.setData({
                        huifu_kai: false,
                        photo: [],
                        huifu_con: ''
                    })
                    that.getXq(that.data.xqList.id)
                }, 1000)
            }
        })
    },
    getXq(id) {
        wx.showLoading({
            title: '加载中',
            icon: 'icon'
        })
        this.myRequest(yuming + 'Jinghexincheng/super_patrol_offpatrol_hflog', {
            id: id
        }, 'POST').then(res => {
            wx.hideLoading();
            // var leng = res.data.data.OffpatrolHflog.length
            if (res.data.code == 200) {
                this.setData({
                    xqList: res.data.data,
                })
                // if (leng > 0) {
                //     this.setData({
                //         zuihuista: res.data.data.OffpatrolHflog[leng - 1].hf_status
                //     })
                // }
                // this.data.checkresult.forEach(item => {
                //     if (this.data.xqList.inspect == item.name) {
                //         item.checked = true;
                //     }
                // })
                // this.data.reschuli.forEach(item => {
                //     if (this.data.xqList.patrol == item.name) {
                //         item.checked = true;
                //     }
                // })
                // this.setData({
                //     checkresult: this.data.checkresult,
                //     reschuli: this.data.reschuli,
                //     huibi: this.data.xqList.shop_huibi,
                //     yijian: this.data.xqList.shop_yijian
                // })
            }
        })
    },
    // 线下
    kindToggles(e) {
        console.log(e)
        const id = e.currentTarget.dataset.id
        const index = e.currentTarget.dataset.index
        console.log(index);
        const pcontent = this.data.xqList.rectification
        console.log(pcontent);
        for (let i = 0, len = pcontent.length; i < len; ++i) {
            if (i == index) {
                pcontent[i].open = !pcontent[i].open
            } else {
                pcontent[i].open = false
            }
        }
        this.setData({
            xqList: this.data.xqList
        })
        console.log(this.data.xqList);
    },
    backs() {
        wx.navigateBack({
            delta: 1
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            heights: wx.getMenuButtonBoundingClientRect().top + 5,
            title: options.title,
            fuid: options.id
        })
        this.getXq(options.id);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },
})